<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
  <title>欢迎使用领捷智慧物流管理系统</title>
  <link rel="hshortcut icon" href="../static/img/own/head.png"/>
  <link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i">
  <link rel="stylesheet" href="/static/fonts/fontawesome-all.min.css">
</head>

<body>
<div id="wrapper">
  <div class="d-flex flex-column" id="content-wrapper">
    <div id="content">
      <div class="container border rounded" style="min-width: 100%;width: auto;margin-bottom: 0px;padding: 0px;padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;height: auto;margin-right: 0px;">
        <div class="row" style="margin-right: 0px;margin-left: 0px;">
          <div class="col" style="margin-left: 24px;padding: 13px;background: #ffffff;margin-right: 24px;"><span style="font-size: 25px;color: rgb(0,0,0);padding-left: 0px;">添加货架：</span></div>
        </div>
      </div>
      <div class="container border rounded" style="min-width: 100%;width: auto;margin-bottom: 0px;padding: 0px;padding-top: 0px;padding-right: 0px;padding-bottom: 0px;padding-left: 0px;height: auto;margin-right: 0px;">
        <form id="addShelfForm"  method="post" onsubmit="return fabu(this)" class="border rounded d-inline-flex flex-column justify-content-start justify-content-xl-start" style="background: #ffffff;margin-right: 24px;margin-left: 24px;opacity: 1;margin-top: 4px;padding: 12px;width: 1038px;"><span style="font-size: 18px;color: rgb(0,0,0);margin-left: 21px;margin-top: 0px;padding: 0px;padding-top: 0px;width: auto;">基本信息</span>
          <div class="form-group text-monospace text-center d-inline-flex justify-content-center visible" style="width: auto;padding-right: 0px;"
          ><span style="color: rgb(0,0,0);font-size: 16px;line-height: 40px;">&nbsp;库房编号&nbsp;</span><input class="form-control" type="text" style="width: 350px;margin-left: 10px;" th:value="${houseid}" name="houseid" id="houseid" readonly></div>
          <div class="form-group text-monospace text-center d-inline-flex justify-content-center visible" style="width: auto;padding-right: 0px;"
          ><span style="color: rgb(0,0,0);font-size: 16px;line-height: 40px;">&nbsp;库房名称&nbsp;</span><input class="form-control" type="text" style="width: 350px;margin-left: 10px;" th:value="${housename}" name="housename" id="housename" readonly></div>
          <div class="form-group text-monospace text-center d-inline-flex justify-content-center" style="height: auto;margin-left: 0px;margin-right: 0px;width: auto;max-height: 100%;padding-left: 0px;">
            <span style="color: rgb(0,0,0);line-height: 40px;">输入片区</span>
            <input class="form-control" type="text" style="width: 350px;margin-left: 10px;" name="pianqu" maxlength="1" placeholder="请输入一位大写字母" onkeyup="this.value=this.value.replace(/[^A-Z]/g,'')">
          </div>
          <div class="form-group text-monospace text-center d-inline-flex justify-content-center" style="height: auto;margin-left: 0px;margin-right: 0px;width: auto;max-height: 100%;padding-left: 0px;">
            <span style="color: rgb(0,0,0);line-height: 40px;">输入货架</span>
            <input class="form-control" type="text" style="width: 350px;margin-left: 10px;" name="huojia" maxlength="1" placeholder="请输入1-9中的一位数字" onkeyup="this.value=this.value.replace(/[^1-9]/g,'')">
          </div>
          <div class="form-group text-monospace text-center d-inline-flex justify-content-center" style="height: auto;margin-left: 0px;margin-right: 0px;width: auto;max-height: 100%;padding-left: 0px;">
            <span style="color: rgb(0,0,0);line-height: 40px;">输入货架号</span>
            <input class="form-control" type="text" style="width: 350px;margin-left: 10px;" maxlength="3" name="huojiahao" placeholder="请输入1-999作为货架号" onkeyup="this.value=this.value.replace(/^0|[^0-9]/g,'')">
          </div>

          <div class="form-group text-monospace text-center d-inline-flex justify-content-center"
               style="height: auto;margin-left: 0px;margin-right: 0px;width: auto;max-height: 100%;padding-left: 0px;">
            <button class="btn btn-primary" style="width: 80px;" type="submit" value="fabu">发布</button>
            <button class="btn btn-primary" type="button" style="width: 80px;margin-left: 10px;" id="goBack">返回</button></div>
        </form>
      </div>
    </div>
    <footer class="bg-white sticky-footer">
      <div class="container my-auto">
        <div class="text-center my-auto copyright"><span>鄂ICP备2021022432号</span></div>
      </div>
    </footer>
  </div><a class="border rounded d-inline scroll-to-top" href="#page-top"><i class="fas fa-angle-up"></i></a></div>
<script src="/static/js/jquery.min.js"></script>
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
<script src="/static/js/chart.min.js"></script>
<script src="/static/js/bs-init.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.js"></script>
<script src="/static/js/theme.js"></script>
<script src="/static/js/jquery.session.js"></script>


<script>
  var houseid = $("#houseid").val();
  var housename = $("#housename").val();
  var isnull = true;
  //判断input是否为空
  function fabu(formvalue){
    var pianqu = formvalue.pianqu.value;
    var huojia = formvalue.huojia.value;
    var huojiahao = formvalue.huojiahao.value;
    if(0==pianqu||0==huojia||0==huojiahao){
      isnull = false;
      alert("请不要输入空值！");
      return false;
    }
  }

    //先判断货架是否存在，再添加货架
    $(function () {
    $('#addShelfForm').on('submit', function (e) {
      e.preventDefault();
      if(isnull == false){
        isnull = true;
        return false;
      }
      $.ajax({
        type: 'POST',
        url: '/shelf/judgeShelf',
        data: $('#addShelfForm').serialize(),
        success: function(response) {
          if(response == "fail"){
            alert("货架已存在！");
            return false;
          }else if(response == "success"){
            $.ajax({
              type: 'POST',
              url: '/shelf/addShelf',
              data: $('#addShelfForm').serialize(),
              success: function(result) {
                if(result == "success"){
                  alert("添加成功！");
                  $(location).attr("href","/warehouse/toShelf?houseid="+houseid+"&housename="+housename);
                }
              }
            });
          }
        }
      });
    })
  })

  //返回
  $(function (){
    $("#goBack").on("click",function (){
      $(location).attr("href","/warehouse/toShelf?houseid="+houseid+"&housename="+housename);
    })
  })


  //session
  $.session.set("url",window.location.href);

</script>
</body>

</html>